import time

from playwright.sync_api import sync_playwright

def run(playwright):
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()

    # Open new page
    page = context.new_page()

    # Go to http://localhost:3000/user/login
    page.goto("http://localhost:3000/user/login")

    # Click [placeholder="请输入帐户名 / admin"]
    page.click("[placeholder=\"请输入帐户名 / admin\"]")

    # Fill [placeholder="请输入帐户名 / admin"]
    page.fill("[placeholder=\"请输入帐户名 / admin\"]", "admin")

    # Press Tab
    page.press("[placeholder=\"请输入帐户名 / admin\"]", "Tab")

    # Fill [placeholder="密码 / 123456"]
    page.fill("[placeholder=\"密码 / 123456\"]", "123456")

    # Press Tab
    page.press("[placeholder=\"密码 / 123456\"]", "Tab")

    # Fill [placeholder="请输入验证码"]
    page.fill("[placeholder=\"请输入验证码\"]", "6666")

    # Click button:has-text("确 定")
    page.click("button:has-text(\"确 定\")")


    # Click ul[role="menu"] div:has-text("动员命令管理")
    page.click("ul[role=\"menu\"] div:has-text(\"动员命令管理\")")

    # Click a:has-text("创建动员命令")
    page.click("a:has-text(\"创建动员命令\")")
    # assert page.url == "http://localhost:3000/deploy/command/CreateCommand"

    # Click button:has-text("选择文件")
    # page.click("button:has-text(\"选择文件\")")

    # time.sleep(30)
    # Upload 警备项目演示文档命令.pdf
    page.set_input_files("#app > section > section > main > div:nth-child(3) > div > div > div > div > div > div > div > div:nth-child(2) > div > div > div > div > div > fieldset:nth-child(1) > form > div > div:nth-child(1) > div > div.ant-col.ant-col-xs-24.ant-col-sm-12.ant-form-item-control-wrapper > div > span > span > div.ant-upload.ant-upload-select.ant-upload-select-text > span > input[type=file]",
                         "C:/Users/acmis/Desktop/JBQ/demo.pdf")

    # Click button:has-text("解析命令文件")
    page.click("button:has-text(\"解析命令文件\")")

    time.sleep(20000)
    # ---------------------
    context.close()
    browser.close()

with sync_playwright() as playwright:
    run(playwright)